home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / libs / kpathsea / lib.h < prev    next >
C/C++ Source or Header  |  1995-06-25  |  6KB  |  155 lines

  1. /* lib.h: declarations for common, low-level routines in kpathsea.
  2.  
  3. Copyright (C) 1992, 93, 94 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  */
  18.  
  19. #ifndef KPATHSEA_LIB_H
  20. #define KPATHSEA_LIB_H
  21.  
  22. #include <kpathsea/types.h>
  23.  
  24. /* Define common sorts of messages.  */
  25.  
  26. /* This should be called only after a system call fails.  Don't exit
  27.    with status `errno', because that might be 256, which would mean
  28.    success (exit statuses are truncated to eight bits).  */
  29. #define FATAL_PERROR(s) do { perror (s); exit (EXIT_FAILURE); } while (0)
  30.  
  31.  
  32. #define START_FATAL() do { fputs ("fatal: ", stderr)
  33. #define END_FATAL() fputs (".\n", stderr); exit (1); } while (0)
  34.  
  35. #define FATAL(str)                            \
  36.   START_FATAL (); fputs (str, stderr); END_FATAL ()
  37. #define FATAL1(str, e1)                            \
  38.   START_FATAL (); fprintf (stderr, str, e1); END_FATAL ()
  39. #define FATAL2(str, e1, e2)                        \
  40.   START_FATAL (); fprintf (stderr, str, e1, e2); END_FATAL ()
  41. #define FATAL3(str, e1, e2, e3)                        \
  42.   START_FATAL (); fprintf (stderr, str, e1, e2, e3); END_FATAL ()
  43. #define FATAL4(str, e1, e2, e3, e4)                    \
  44.   START_FATAL (); fprintf (stderr, str, e1, e2, e3, e4); END_FATAL ()
  45. #define FATAL6(str, e1, e2, e3, e4, e5, e6)                \
  46.   START_FATAL (); fprintf (stderr, str, e1, e2, e3, e4, e5, e6); END_FATAL ()
  47.  
  48.  
  49. #define START_WARNING() do { fputs ("warning: ", stderr)
  50. #define END_WARNING() fputs (".\n", stderr); fflush (stderr); } while (0)
  51.  
  52. #define WARNING(str)                            \
  53.   START_WARNING (); fputs (str, stderr); END_WARNING ()
  54. #define WARNING1(str, e1)                        \
  55.   START_WARNING (); fprintf (stderr, str, e1); END_WARNING ()
  56. #define WARNING2(str, e1, e2)                        \
  57.   START_WARNING (); fprintf (stderr, str, e1, e2); END_WARNING ()
  58. #define WARNING3(str, e1, e2, e3)                    \
  59.   START_WARNING (); fprintf (stderr, str, e1, e2, e3); END_WARNING ()
  60. #define WARNING4(str, e1, e2, e3, e4)                    \
  61.   START_WARNING (); fprintf (stderr, str, e1, e2, e3, e4); END_WARNING ()
  62.  
  63.  
  64. /* I find this easier to read.  */
  65. #define STREQ(s1, s2) (strcmp (s1, s2) == 0)
  66.  
  67. /* This is the maximum number of numerals that result when a 64-bit
  68.    integer is converted to a string, plus one for a trailing null byte,
  69.    plus one for a sign.  */
  70. #define MAX_INT_LENGTH 21
  71.  
  72. /* If the environment variable TEST is set, return it; otherwise,
  73.    DEFAULT.  This is useful for paths that use more than one envvar.  */
  74. #define ENVVAR(test, default) (getenv (test) ? (test) : (default))
  75.  
  76. /* Return a fresh copy of S1 followed by S2, et al.  */
  77. extern string concat P2H(const_string s1, const_string s2);
  78. extern string concat3 P3H(const_string, const_string, const_string);
  79. /* `concatn' is declared in its own include file, to avoid pulling in
  80.    all the varargs stuff.  */
  81.  
  82. /* A fresh copy of just S.  */
  83. extern string xstrdup P1H(const_string s);
  84.  
  85. /* Convert all lowercase characters in S to uppercase.  */
  86. extern string uppercasify P1H(const_string s);
  87.  
  88. /* Convert the integer I to a string.  */
  89. extern string itoa P1H(int i);
  90.  
  91. /* True if FILENAME1 and FILENAME2 are the same file.  If stat fails on
  92.    either name, return false, no error message.
  93.    Cf. `SAME_FILE_P' in xstat.h.  */
  94. extern boolean same_file_p P2H(const_string filename1, const_string filename2);
  95.  
  96. #ifndef HAVE_BASENAME
  97. /* Return NAME with any leading path stripped off.  This returns a
  98.    pointer into NAME.  */
  99. extern const_string basename P1H(const_string name);
  100. #endif /* not HAVE_BASENAME */
  101.  
  102. /* If NAME has a suffix, return a pointer to its first character (i.e.,
  103.    the one after the `.'); otherwise, return NULL.  */
  104. extern string find_suffix P1H(const_string name);
  105.  
  106. /* Return NAME with any suffix removed.  */
  107. extern string remove_suffix P1H(const_string name);
  108.  
  109. /* Return S with the suffix SUFFIX, removing any suffix already present.
  110.    For example, `make_suffix ("/foo/bar.baz", "karl")' returns
  111.    `/foo/bar.karl'.  Returns a string allocated with malloc.  */
  112. extern string make_suffix P2H(const_string s,  const_string suffix);
  113.  
  114. /* Return NAME with STEM_PREFIX prepended to the stem. For example,
  115.    `make_prefix ("/foo/bar.baz", "x")' returns `/foo/xbar.baz'.
  116.    Returns a string allocated with malloc.  */
  117. extern string make_prefix P2H(string stem_prefix, string name);
  118.  
  119. /* If NAME has a suffix, simply return it; otherwise, return
  120.    `NAME.SUFFIX'.  */
  121. extern string extend_filename P2H(const_string name, const_string suffix);
  122.  
  123. /* Call putenv with the string `VAR=VALUE' and abort on error.  */
  124. extern void xputenv P2H(const_string var, const_string value);
  125. extern void xputenv_int P2H(const_string var, int value);
  126.  
  127. /* Returns true if FN is a directory or a symlink to a directory.  */
  128. extern boolean dir_p P1H(const_string fn);
  129.  
  130. /* If FN is a readable directory, return the number of links it has.
  131.    Otherwise, return -1.  */
  132. extern int dir_links P1H(const_string fn);
  133.  
  134. /* Like their stdio counterparts, but abort on error, after calling
  135.    perror(3) with FILENAME as its argument.  */
  136. extern FILE *xfopen P2H(const_string filename, const_string mode);
  137. extern void xfclose P2H(FILE *, const_string filename);
  138. extern void xfseek P4H(FILE *, long, int, string filename);
  139. extern unsigned long xftell P2H(FILE *, string filename);
  140.  
  141.  
  142. /* These call the corresponding function in the standard library, and
  143.    abort if those routines fail.  Also, `xrealloc' calls `xmalloc' if
  144.    OLD_ADDRESS is null.  */
  145. extern address xmalloc P1H(unsigned size);
  146. extern address xrealloc P2H(address old_address, unsigned new_size);
  147. extern address xcalloc P2H(unsigned nelem, unsigned elsize);
  148.  
  149. /* (Re)Allocate N items of type T using xmalloc/xrealloc.  */
  150. #define XTALLOC(n, t) ((t *) xmalloc ((n) * sizeof (t)))
  151. #define XTALLOC1(t) XTALLOC (1, t)
  152. #define XRETALLOC(addr, n, t) ((addr) = (t *) xrealloc (addr, (n) * sizeof(t)))
  153.  
  154. #endif /* not KPATHSEA_LIB_H */
  155.